package com.huawei.appgallery.foundation.ui.framework.widget;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
import java.lang.ref.WeakReference;
import kotlin.Metadata;
import o.fsd;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000F\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\r\u0018\u0000 \"2\u00020\u0001:\u0003\"#$B\u000f\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004B\u0019\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007B!\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nB)\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\u000b\u001a\u00020\t¢\u0006\u0002\u0010\fJ\u0010\u0010\u0014\u001a\u00020\u000e2\u0006\u0010\u0015\u001a\u00020\u0016H\u0016J(\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\t2\u0006\u0010\u001a\u001a\u00020\t2\u0006\u0010\u001b\u001a\u00020\t2\u0006\u0010\u001c\u001a\u00020\tH\u0014J\u0010\u0010\u001d\u001a\u00020\u000e2\u0006\u0010\u0015\u001a\u00020\u0016H\u0016J\b\u0010\u001e\u001a\u00020\u0018H\u0002J\u0010\u0010\u001f\u001a\u00020\u00182\u0006\u0010 \u001a\u00020\tH\u0002J\u0010\u0010!\u001a\u00020\u00182\b\u0010\u0010\u001a\u0004\u0018\u00010\u0011R\u000e\u0010\r\u001a\u00020\u000eX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0010\u001a\u0004\u0018\u00010\u0011X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\u0013X\u0004¢\u0006\u0002\n\u0000¨\u0006%"}, d2 = {"Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView;", "Landroid/widget/ScrollView;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "attrs", "Landroid/util/AttributeSet;", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "defStyleRes", "(Landroid/content/Context;Landroid/util/AttributeSet;II)V", "isBeingTouching", "", "scrollState", "scrollStateListener", "Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$ScrollStateListener;", "stateChangeHandler", "Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$StateChangeHandler;", "onInterceptTouchEvent", "ev", "Landroid/view/MotionEvent;", "onScrollChanged", "", "l", "t", "oldl", "oldt", "onTouchEvent", "scheduleScrollEndCheck", "setScrollState", "state", "setScrollStateListener", "Companion", "ScrollStateListener", "StateChangeHandler", "HiAppBase_release"}, k = 1, mv = {1, 1, 15})
public final class ObservableScrollView extends ScrollView {
    public static final c ˏ = new c();
    private boolean ˊ;
    private a ˋ;
    private final StateChangeHandler ˎ = new StateChangeHandler(new WeakReference(this));
    private int ॱ;

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\bf\u0018\u0000 \b2\u00020\u0001:\u0001\bJ\u0018\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u00052\u0006\u0010\u0006\u001a\u00020\u0007H&¨\u0006\t"}, d2 = {"Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$ScrollStateListener;", "", "onScrollStateChanged", "", "view", "Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView;", "scrollState", "", "Companion", "HiAppBase_release"}, k = 1, mv = {1, 1, 15})
    public interface a {
        public static final d ˊ = d.ॱ;

        @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000¨\u0006\u0007"}, d2 = {"Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$ScrollStateListener$Companion;", "", "()V", "SCROLL_STATE_FLING", "", "SCROLL_STATE_IDLE", "SCROLL_STATE_TOUCH_SCROLL", "HiAppBase_release"}, k = 1, mv = {1, 1, 15})
        public static final class d {
            static final /* synthetic */ d ॱ = new d();

            private d() {
            }
        }

        void ˋ(@NotNull ObservableScrollView observableScrollView, int i);
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u0013\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005J\u0010\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\rH\u0016R\u000e\u0010\u0006\u001a\u00020\u0007X\u000e¢\u0006\u0002\n\u0000R\u0017\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\t¨\u0006\u000e"}, d2 = {"Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$StateChangeHandler;", "Landroid/os/Handler;", "scrollViewRef", "Ljava/lang/ref/WeakReference;", "Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView;", "(Ljava/lang/ref/WeakReference;)V", "lastY", "", "getScrollViewRef", "()Ljava/lang/ref/WeakReference;", "handleMessage", "", "msg", "Landroid/os/Message;", "HiAppBase_release"}, k = 1, mv = {1, 1, 15})
    static final class StateChangeHandler extends Handler {
        private int ˋ = Integer.MIN_VALUE;
        @NotNull
        private final WeakReference<ObservableScrollView> ˎ;

        public StateChangeHandler(@NotNull WeakReference<ObservableScrollView> weakReference) {
            fsd.ˊ(weakReference, "scrollViewRef");
            this.ˎ = weakReference;
        }

        public void handleMessage(@NotNull Message message) {
            fsd.ˊ(message, "msg");
            ObservableScrollView observableScrollView = (ObservableScrollView) this.ˎ.get();
            if (observableScrollView != null) {
                fsd.ॱ(observableScrollView, "scrollViewRef.get() ?: return");
                if (message.what == 1) {
                    int scrollY = observableScrollView.getScrollY();
                    if (observableScrollView.ˊ || this.ˋ != scrollY) {
                        this.ˋ = scrollY;
                        observableScrollView.ˏ();
                        return;
                    }
                    this.ˋ = Integer.MIN_VALUE;
                    observableScrollView.ˊ(0);
                }
            }
        }
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\t\n\u0000\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006XT¢\u0006\u0002\n\u0000¨\u0006\u0007"}, d2 = {"Lcom/huawei/appgallery/foundation/ui/framework/widget/ObservableScrollView$Companion;", "", "()V", "MSG_SCROLL_END_CHECK", "", "SCROLL_END_CHECK_DELAY", "", "HiAppBase_release"}, k = 1, mv = {1, 1, 15})
    public static final class c {
        private c() {
        }
    }

    public ObservableScrollView(@NotNull Context context) {
        fsd.ˊ(context, "context");
        super(context);
    }

    public ObservableScrollView(@NotNull Context context, @Nullable AttributeSet attributeSet) {
        fsd.ˊ(context, "context");
        super(context, attributeSet);
    }

    public ObservableScrollView(@NotNull Context context, @Nullable AttributeSet attributeSet, int i) {
        fsd.ˊ(context, "context");
        super(context, attributeSet, i);
    }

    public final void setScrollStateListener(@Nullable a aVar) {
        this.ˋ = aVar;
    }

    private final void ˏ() {
        this.ˎ.removeMessages(1);
        this.ˎ.sendEmptyMessageDelayed(1, 100);
    }

    public boolean onInterceptTouchEvent(@NotNull MotionEvent motionEvent) {
        fsd.ˊ(motionEvent, "ev");
        switch (motionEvent.getAction()) {
            case 0:
                this.ˊ = true;
                break;
        }
        return super.onInterceptTouchEvent(motionEvent);
    }

    public boolean onTouchEvent(@NotNull MotionEvent motionEvent) {
        fsd.ˊ(motionEvent, "ev");
        switch (motionEvent.getAction()) {
            case 1:
            case 3:
                this.ˊ = false;
                ˏ();
                break;
        }
        return super.onTouchEvent(motionEvent);
    }

    protected void onScrollChanged(int i, int i2, int i3, int i4) {
        super.onScrollChanged(i, i2, i3, i4);
        if (this.ˊ) {
            ˊ(1);
            return;
        }
        ˊ(2);
        ˏ();
    }

    private final void ˊ(int i) {
        if (this.ॱ != i) {
            this.ॱ = i;
            a aVar = this.ˋ;
            if (aVar != null) {
                aVar.ˋ(this, i);
            }
        }
    }
}
